qui {

	* Required package - rdrobust
	*net install st0366_1.pkg


	* Restricted relication data
	u restricteddata, clear

	* FRD estimates for low income group
	rdrobust crime_adm10 std_admscore if low20==1, vce(cluster id) all ///
		fuzzy(enrolled)
	loc tau1 = round(e(tau_bc),.001)


	* FRD estimates for low income group in high SES programs
	rdrobust crime_adm10 std_admscore if lowSESprog_inc==0 & low20==1 & ///
		employed_adm10==1, vce(cluster id) fuzzy(enrolled) all
	loc tau2 = round(e(tau_bc),.001)


	* Dataset of all nonadmitted candidates
	u nonadmitted, clear

	* % Increase in admissions
	loc T
	forv t=10(20)70 {
		loc T "`T' `t'"
	}
	loc T "`T' 100"
	foreach t in `T' { // % increase in admissions	
		g _c`t' = . // variable to mark admitted students
	}

	* Note: all total numbers are divided by 2 because data includes 2 cohorts

	****************************************************************************
	* Impact on low income applicants - No quota
	****************************************************************************
	
	* Number of additional students admitted
	foreach t in `T' { // % increase in admissions	
		replace _c`t' = (p_nad<`t')/2
	}
	total _c*
	est store V

	* Number of additional low income students admitted
	foreach t in `T' {	
		replace _c`t' = cond(p_nad<`t' & low20==1, 1, 0)/2
	}
	total _c*
	est store L
	
	* Average crime rate minus effect
	* (only those in the restricted sample are assumed to be affected)
	foreach t in `T' { 
		replace _c`t' = cond(p_nad<`t' & sample==1, crime_adm10 + `tau1', ///
			cond(low20==1, crime_adm10,.))
	}
	mean crime_adm10 _c* if low20==1
	est store M

	* Number of low income students out of crime 
	* (only those in the restricted sample are assumed to be affected)
	foreach t in `T' {	
		replace _c`t' = cond(p_nad<`t' & low20==1 & sample==1, -`tau1', 0)/2
	}
	total _c*
	est store S

	****************************************************************************
	* Impact on low income applicants in high SES programs - No quota
	****************************************************************************

	* Average crime rate minus effect
	* (only those in the restricted sample are assumed to be affected)	
	foreach t in `T' {	
		replace _c`t' = cond(p_nad<`t' & sample==1 & lowSESprog_inc==0, ///
			crime_adm10 + `tau2', cond(low20==1, crime_adm10,.))
	}
	mean crime_adm10 _c* if low20==1
	est store M2

	* Number of low income students out of crime 
	* (only those in the restricted sample are assumed to be affected)
	foreach t in `T' {	
		replace _c`t' = cond(p_nad<`t' & sample==1 & lowSESprog_inc==0 & low20==1, ///
			-`tau2', 0)/2
	}
	total _c*
	est store S2


	* Panel A - No quotas
	noi di ""
	noi di "Panel A. No quotas"
	noi estout V L M S M2 S2, c(b(fmt(%9.2g))) sty(tex)
	noi di ""

	
	****************************************************************************
	* Impact on low income applicants - Quota for public school students
	****************************************************************************

	* Number of additional students admitted
	foreach t in `T' {	
		replace _c`t' = (p_nad_pub<`t')/2
	}
	total _c*
	est store V

	* Number of additional low income students admitted
	foreach t in `T' {	
		replace _c`t' = cond(p_nad_pub<`t' & low20==1 & sample==1, 1, 0)/2
	}
	total _c*
	est store L

	* Average crime rate minus effect
	* (only those in the restricted sample are assumed to be affected)
	foreach t in `T' {	
		replace _c`t' = cond(p_nad_pub<`t' & sample==1, ///
			crime_adm10 + `tau1', cond(low20==1, crime_adm10,.))
	}
	mean crime_adm10 _c* if low20==1
	est store M

	* Number of low income students out of crime 
	* (only those in the restricted sample are assumed to be affected)
	foreach t in `T' {	
		replace _c`t' = cond(p_nad_pub<`t' & low20==1 & sample==1, -`tau1', 0)/2
	}
	total _c*
	est store S

	****************************************************************************
	* Impact on low income applicants in high SES programs - Quota pub schools
	****************************************************************************

	* Average crime rate minus effect
	* (only those in the restricted sample are assumed to be affected)	
	foreach t in `T' {	
		replace _c`t' = cond(p_nad_pub<`t' & sample==1 & lowSESprog_inc==0, ///
			crime_adm10 + `tau2', cond(low20==1, crime_adm10,.))
	}
	mean crime_adm10 _c* if low20==1
	est store M2

	* Number of low income students out of crime 
	* (only those in the restricted sample are assumed to be affected)
	foreach t in `T' {	
		replace _c`t' = cond(p_nad_pub<`t' & sample==1 & lowSESprog_inc==0 ///
			& low20==1, -`tau2', 0)/2
	}
	total _c*
	est store S2


	* Panel B - Quotas for public schools
	noi di ""
	noi di "Panel B. Quotas for public schools"
	noi estout V L M S M2 S2, c(b(fmt(%9.2g))) sty(tex)
	noi di ""

	
	****************************************************************************
	* Impact on low income applicants - Quota for Black and Indigenous students
	****************************************************************************

	* Number of additional students admitted
	foreach t in `T' {	
		replace _c`t' = (p_nad_race<`t')/2
	}
	total _c*
	est store V

	* Number of additional low income students admitted
	foreach t in `T' {	
		replace _c`t' = cond(p_nad_race<`t' & low20==1, 1, 0)/2
	}
	total _c*
	est store L

	* Average crime rate minus effect
	* (only those in the restricted sample are assumed to be affected)
	foreach t in `T' {	
		replace _c`t' = cond(p_nad_race<`t' & sample==1, crime_adm10 + `tau1', ///
			cond(low20==1, crime_adm10,.))
	}
	mean crime_adm10 _c* if low20==1
	est store M

	* Number of low income students out of crime 
	* (only those in the restricted sample are assumed to be affected)	
	foreach t in `T' {	
		replace _c`t' = cond(p_nad_race<`t' & low20==1 & sample==1, - `tau1', 0)/2
	}
	total _c*
	est store S
	
	****************************************************************************
	* Impact on low income applicants in high SES programs - Racial quotas
	****************************************************************************

	* Average crime rate minus effect
	* (only those in the restricted sample are assumed to be affected)
	foreach t in `T' {	
		replace _c`t' = cond(p_nad_race<`t' & sample==1 & lowSESprog_inc==0, ///
			crime_adm10 + `tau2', cond(low20==1, crime_adm10,.))
	}
	mean crime_adm10 _c* if low20==1
	est store M2

	* Number of low income students out of crime 
	* (only those in the restricted sample are assumed to be affected)
	foreach t in `T' {	
		replace _c`t' = cond(p_nad_race<`t' & sample==1 & lowSESprog_inc==0 ///
			& low20==1, -`tau2', 0)/2
	}
	total _c*
	est store S2

	
	* Panel C - Quotas for Black and Indigenous students
	noi di ""
	noi di "Panel C. Quotas for race"
	noi estout V L M S M2 S2, c(b(fmt(%9.2g))) sty(tex)
}
